const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    stuname:'',
    classid:'',
    
    list:[],
    count:''
  },

  name:function(e){
    console.log(e);
    this.setData({
      stuname:e.detail.value,
      page:1
    })
    this.getlist()
  },
  delete:function(){
    this.setData({
      stuname:''
    })
    this.getlist()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let that = this
    if(options.class_id){
      that.setData({
        classid:options.class_id
      })
    }
    
    that.getlist()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideHomeButton()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    var page = that.data.page + 1
    that.setData({
      page: page
    })
    that.getlist()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

    goindex: function () {
      wx.reLaunch({
        url: '../yzindex/index'
      })
    },
    gomine: function () {
      wx.reLaunch({
        url: '../yzmine/mine'
      })
    },
    getlist: function () {
      var that = this
      wx.showLoading({
        title: '正在加载中',
      })
      wx.getStorage({
        key: 'yzuser',
        success: function (res) {
          console.log(res)
          let setdata = {
            token: res.data.token,
            page: that.data.page,
            limit: that.data.limit,
            stuname:that.data.stuname,
            classs_id:that.data.classid
          }
          console.log(setdata)
          wx.request({
            url: app.api + app.yzstudent,
            method: 'POST',
            data: setdata,
            success(e) {
              console.log(e)
              wx.hideLoading()
              if (e.data.code == 0) {
                if (that.data.page == 1) {
                  that.setData({
                    count:e.data.data.count,
                    list: e.data.data.list
                  })
                  if (!e.data.data.list.length) {
                    wx.showToast({
                      title: '暂无数据',
                      icon: "none",
                      duration: 2000
                    })
                  }
                } else if (e.data.data.list.length) {
                  let list = that.data.list
                  list = list.concat(e.data.data.list)
                  that.setData({
                    list: list
                  })
                  console.log(that.data.list)
                } else {
                  wx.showToast({
                    title: '没有更多了',
                    icon: 'none',
                    duration: 2000
                  })
                }
              } else if (e.data.code == -1) {
                wx.redirectTo({
                  url: '../yzlogin/login'
                })
              } else {
                wx.showToast({
                  title: res.data.msg,
                })
              }
            }
          })
        }
         
      })
    }




})